<template>
	<view class="body">
		<xk-header :headerbg="true" class="header" :back="true" title="公告消息"></xk-header>

		<!-- <view class="tabs-bar" scroll-x="true">
			<view v-for="(item, index) of tabs" :key="index" :class="tabIndex === index ? 'item item-a' : 'item'" @click="clickTab(index)" >{{item.title}}</view>
		</view> -->
		<view>
			<swiper @change="listInfoChange" :current="tabIndex"
				:style="{height: scrollViewHeight + 'px'}">
				<swiper-item v-for="(tabItem, tabIndex) of tabs" :key="tabIndex">
					<scroll-view class="data-list" scroll-y="true">
						<view class="list-info" v-for="(item, index) of dataList[tabIndex]" :key="index"
							 v-if="tabIndex===0">
							<view class="time">{{item.enable_time.split(" ")[1]}}</view>
							<view class="list-item" @click="goNoticDetail(item)">
								<view class="title">{{item.name}}</view>
								<view class="sec-title-view">
									<view>{{item.publish_dept}}</view>
									<view>{{item.enable_time}}</view>
								</view>
								<text space="nbsp">{{formatContent(item.content)}}</text>
							</view>
						</view>

						<view class="list-info" v-for="(item, index) of dataList[tabIndex]" :key="index"
							 v-if="tabIndex === 1">
							<view class="list-item" @click="goDetail(item)">
								<view class="jf-header">
									<view>合同编号:HT202105310001</view>
									<view class="time">05月30日 10:59</view>
								</view>
								<text space="nbsp">{{item.content}}</text>
								<view class="warning">
									未缴费合同编号: HT202105310003
								</view>
								<view class="btn-bar">
									<view class="btn-s">查看详情</view>
								</view>
							</view>
						</view>
						<view class="list-info" v-for="(item, index) of dataList[tabIndex]" :key="index"
							 v-if="tabIndex === 3">
							<view class="list-item" @click="goDetail(item)">
								<view class="jf-header">
									<view>合同编号:HT202105310001</view>
									<view class="time-l">2021年5月</view>
								</view>
								<text space="nbsp">{{item.content}}</text>
								<view class="warning">
									未缴费合同编号: HT202105310003
								</view>
								<view class="btn-bar">
									<view class="btn-s">查看详情</view>
								</view>
							</view>
						</view>
						<view class="empty-view" v-if="!dataList[tabIndex] || dataList[tabIndex].length <= 0">
							<image class="empty-icon" :src="(imgUrl+'/wx/empty_data_icon.png')"></image>
							<view>哎呀，该界面暂无内容~</view>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
		<!-- <view class="list-info" v-for="(item, index) of dataList" :key="index"
			 v-if="dataList || dataList > 0">
			<view class="time">{{item.date.split(" ")[1]}}</view>
			<view class="list-item" @click="goDetail(item)">
				<view class="title">{{item.title}}</view>
				<view class="sec-title-view">
					<view>{{item.author}}</view>
					<view>{{item.date.split(" ")[0]}}</view>
				</view>
				<text space="nbsp">{{item.content}}</text>
			</view>
		</view>

		<view class="empty-view" v-if="!dataList || dataList <= 0">
			<image class="empty-icon" src="/static/empty_data_icon.png"></image>
			<view>哎呀，该界面暂无内容~</view>
		</view> -->
	</view>
</template>
<script>
	import config from '@/common/config.js'
	import moment from 'moment'

	export default {
		data() {
			return {
				imgUrl:this.$config.BASE_imgUrl,
				scrollViewHeightBottom: 0,
				scrollViewHeight: 0,
				tabIndex: 0,
				tabs: [{
					title: "园区公告",
					type: ""
				}],
				dataList: [[], [], []]
			};
		},
		onLoad(options) {
			this.initInfo()
		},
		onShow() {
			this.$util.getHeightWithTopEl(".header").then(height => {
				this.scrollViewHeight = height;
			});
		},
		methods:{
			initInfo() {
				let query = this.$util.formatGraphqlQuery([{
					fun: "placardList:index_getMbPlacard",	// 消息公告列表
					params: {},
					result: "name, content,  publish_dept, publisher, enable_time"
				}])
				this.$util.postGraphql({query}).then((res)=>{
					console.warn("消息公告请求列表：", res.placardList)

					for (let item of res.placardList) {
						this.dataList[0].push(item)
					}
				})
			},
			listInfoChange(e){
				this.tabIndex = parseInt(e.target.current)
			},
			clickTab(index){
				this.tabIndex = index
			},
			formatContent(content) {
				if (content && content.length > 100) {
					content = content.substr(0, 100) + "..."
				}
				return content
			},
			goNoticDetail(item) {
				uni.navigateTo({
					url: "/pagesC/notice/notice-detail?data=" + JSON.stringify(item)
				})
			}
		}
	}
</script>

<style lang="scss">
.tabs-bar{
	display: flex;
	align-items: center;
	flex-direction: row;
	justify-content: space-between;
	padding: 20rpx 30rpx 0rpx 30rpx;
	width: 750rpx;
	background-color: #FFFFFF;
	white-space: nowrap;
	.item{
		display: inline-block;
		height: 65rpx;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
		margin-right: 60rpx;
		color: #333333;
		border-bottom: 6rpx solid rgba(#2C72FF, 0);
	}
	.item-a {
		font-weight: bolder;
		border-bottom: 6rpx solid #2C72FF;
	}
}
.data-list{
	height: 100%;
}
.list-info {
	margin: 20rpx 20rpx 0rpx 20rpx;


	.time {
		text-align: center;
		color: #999;
		font-size: 24rpx;
	}
	.list-item {
		background-color: #FFFFFF;
		border-radius: 10rpx;
		font-size: 28rpx;
		color: #757A82;
		padding: 40rpx 30rpx 50rpx 30rpx;
		margin-top: 10rpx;
		.jf-header{
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 28rpx;
			color: #333333;
			margin-bottom: 50rpx;
			.time-l{
				font-size: 28rpx;
				color: #333333;
				font-weight: bolder;
			}
		}
		.title {
			color: #333;
			font-size: 32rpx;
			font-weight: bold;
		}
		.warning{
			font-size: 28rpx;
			color: #FF3737;
		}
		.btn-bar{
			display: flex;
			justify-content: flex-end;
			marign-top: 30rpx;
			.btn-s{
				height: 60rpx;
				background: #EEF4FF;
				border-radius: 30rpx;
				font-size: 28rpx;
				color: #2C72FF;
				line-height: 60rpx;
				padding: 0 32rpx;
			}
		}
		.sec-title-view {
			display: flex;
			margin: 20rpx 0rpx;
			align-items: center

			:first-child {
				font-size: 24rpx;
				color: #2C72FF;
			}
			:last-child {
				margin-left: 10rpx;
				color: #999;
				font-size: 24rpx;
			}
		}
	}
}
</style>
